import { useState } from "react";

export function useSearchParam(key: string): string;
export function useSearchParam(key: string, defaultValue: string): string;
export function useSearchParam(key: string, defaultValue?: string) {
  const [param] = useState(() => {
    const search = new URLSearchParams(location.search);
    return search.get(key) || defaultValue;
  });

  return param;
}
